package mymaggi.serienjunkiesmonitor;

import javax.swing.text.*;

public class JTextAreaLimit extends PlainDocument
{
/**
	 * 
	 */
	private static final long serialVersionUID = 7873958593963763968L;

private int limit;
 
// optional uppercase conversion
private boolean toUppercase = false;
 
public JTextAreaLimit()
{
super();
}
 
public JTextAreaLimit(int limit)
{
super();
this.limit = limit;
}
 
public JTextAreaLimit(int limit, boolean upper)
{
super();
this.limit = limit;
toUppercase = upper;
}
 
public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException
{
if (str == null)
{
return;
}
 
if ((getLength() + str.length()) <= limit)
{
if (toUppercase)
{
str = str.toUpperCase();
}
super.insertString(offset, str, attr);
}
}
}
